var formData2JsonStr = function(formData){
    var objData = {};
    //(value, key) => objData[key] = value
    formData.forEach(function (curValue,index,arr) {
        objData[index] = curValue;
    });
    //转json字符串
	return objData;
    //return JSON.stringify(objData);
    //转json对象.
    //var objDataStr = JSON.stringify(objData)
    //return JSON.parse(objDataStr);
}

var deleteNameFormData = function (formData,Arr) {
    Arr.forEach(function(value,i){
        formData.delete(value);
    });
    return formData;
}

toastr.options = {
  "closeButton": true,
  "debug": false,
  "progressBar": true,
  "positionClass": "toast-top-center",
  "showDuration": "400",
  "hideDuration": "1000",
  "timeOut": "7000",
  "extendedTimeOut": "1000",
  "showEasing": "swing",
  "hideEasing": "linear",
  "showMethod": "fadeIn",
  "hideMethod": "fadeOut"
}
    //调用方式
//    toastr.error("连接不能打开！");
//    toastr.success("连接已建立，可以进行通信！");
//    toastr.success("连接已建立，可以进行通信！", "成功");
//    toastr.warning("连接建立失败，请重试！");
//    toastr.info("请先登录！");


//var domain = "http://www.iam.sudo:8088/";



//获取页面之间传递的参数
function getQueryString(name) {
    var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
    var r = window.location.search.substr(1).match(reg);
    if (r != null) {
        return decodeURI(r[2]);
    }
    return null;
}

//状态替换 on：启用，off：禁用
function getStatus(str){
	if("ON" == str){
		return '<i class="fa fa-circle text-info"></i>';
	}else if("OFF" == str){
		return '<i class="fa fa-circle text-danger"></i>';
	}else{
		return '-';
	}
}

function getCheckboxes(str){
	var html = '';
		html += '<div class="ckbx-style-13" style="font-size:20px;">';
	if("ON" == str){
		html += '	<input type="checkbox" value="1" checked name="ckbx-style-12">';
	}else if("OFF" == str){
		html += '	<input type="checkbox" value="1" name="ckbx-style-12">';
	}else{
		html += '-';
	}
		html += '	<label for="ckbx-style-12"></label>';
		html += '</div>';
	return html;
}




//系统固有菜单code，只是用来获取锁图标
var menuCodeArr = ["0000","sysRun","userRun","roleRun","menuRun","btnConf",
					"roleAuth","dictRun","sysLogs","user_behavior","user_loginRecord",
					"fileRun","upload_file","myFiles","allFiles"];
function getLock(code){
	var index = menuCodeArr.indexOf(code);
	if(index>=0){
		return '&nbsp;<i class="fa fa-lock" style="color:#DAA520;"></i>';
	}
	return "";

}

//调用父级函数需要关闭弹出框
function callFn(fn,arr){
	var param = "";
	if (arr != undefined){
		for (var i=0;i<arr.length;i++){
			if (arr[i] != undefined){
				if(!!param){
					param += ",";
				}
				if(typeof(arr[i]) == "string"){
					param += "'" + arr[i] + "'";
				}else if(typeof(arr[i]) == "number"){
					param += arr[i];
				}else if(typeof(arr[i]) == "boolean"){
					param += arr[i];
				}
			}
		}
	}
	eval("window.parent."+fn+"("+ param +")");
	closeMyself();
}

function closeMyself(){
	//关闭当前弹窗
	var index = parent.layer.getFrameIndex(window.name);
	parent.layer.close(index);
}

//处理特殊符号的id
function get(id){
	return document.getElementById(id);
}

//睡眠
function sleep(time){
	return new Promise((resolve) => setTimeout(resolve,time));
}
//通过for循环实现睡眠
function sleepByFor(delay){
	for(let start = Date.now();Date.now() - start<delay;);
}
